<?php

namespace app\common\lib\task;

use app\common\lib\ali\Sms;
use app\common\lib\redis\Predis;
use app\common\lib\Redis;

class Task
{

    public function sendSms($data,$ws)
    {
        try{
            $result = Sms::sendSms($data['phone'],$data['code']);
        }catch(\Exception $e){
            return false;
        }
        if($result->Code == 'ok'){
            try{
                Predis::getInstance()->set(Redis::smsKey($data['phone']),$data['code'],config('redis.out_time'));
            }catch(\Exception $e){
                return false;
            }
            return true;
        }else{
            return false;
        }
    }

    public function pushLive($data,$ws)
    {
        $clients = Predis::getInstance()->sMembers(config('redis.live_redis_key'));
        foreach($clients as $fd){
            $ws->push($fd,json_encode($data));
        }
    }

}